Imports System.Data.OleDb

Public Class DataProviderDAO
    Protected connection As OleDbConnection

    Protected Function ConnectionData() As OleDbConnection
        Dim cnStr As String
        cnStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = CSDL.mdb"
        Dim cn As New OleDbConnection(cnStr)
        cn.Open()
        Return cn
    End Function

    Public Function executeQuery(ByVal sql As String) As DataTable
        ConnectionData()
        Dim ds As DataSet
        ds = New DataSet()
        Dim da As New OleDbDataAdapter(sql, connection)
        da.Fill(ds)
        connection.Close()
        Return ds.Tables(0)
    End Function

    'doc cau truc
    Public Function Doc_Cau_Truc(ByVal ten_bang As String) As DataTable
        Dim kq As New DataTable
        Dim Chuoi_ket_noi As String = "Provider = Microsoft.JET.OLEDB.4.0; Data Source = CSDL.mdb"
        Dim Chuoi_lenh As String
        Chuoi_lenh = "select * from " + ten_bang
        Dim Bo_thich_ung As New OleDbDataAdapter(Chuoi_lenh, Chuoi_ket_noi)
        Bo_thich_ung.FillSchema(kq, SchemaType.Source)
        Return kq
    End Function



    'DataProvider.vb cua ...
    Private _strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=CSDL.mdb"
    Public Function Execute(ByVal strSQL As String) As DataTable
        Dim dt As DataTable
        Dim m_Dataset As New DataSet()
        Dim m_OleDbConnection As New OleDbConnection(_strCon)
        Dim m_OleDbDataAdapter As New OleDbDataAdapter()
        m_OleDbDataAdapter.SelectCommand = New OleDbCommand(strSQL, m_OleDbConnection)
        m_OleDbDataAdapter.Fill(m_Dataset)
        m_OleDbConnection.Close()
        dt = m_Dataset.Tables(0)
        Return dt
    End Function
    Public Function ExecuteNonQuery(ByVal strSQL As String) As Integer
        Dim n As Integer
        Dim m_OleDbConnection As New OleDbConnection(_strCon)
        Dim m_OleDBCommand As New OleDbCommand(strSQL, m_OleDbConnection)
        m_OleDbConnection.Open()
        n = m_OleDBCommand.ExecuteNonQuery()
        m_OleDbConnection.Close()
        Return n
    End Function

End Class
